﻿using DayuCode.Designer.Common;
using DayuCode.Designer.Entity;
using DayuCode.Designer.Service;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DayuCode.Designer.Forms
{
    public partial class FormFuncCatalog : UIForm
    {
        Func func;
        public FormFuncCatalog(Func func)
        {
            InitializeComponent();
            if (func == null) throw new HException("func");
            this.func = func;
            txtName.Text = func.Name;
            txtOrdnum.Text = ""+func.Ordnum;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string name = txtName.Text.Trim();
            int ordnum = 0;
            string ordnumStr = txtOrdnum.Text.Trim();
            if (!string.IsNullOrEmpty(ordnumStr))
            {
                ordnum = int.Parse(ordnumStr);
            }
            if (string.IsNullOrEmpty(name))
            {
                ShowErrorTip("名称不能为空");
                return;
            }
            func.Name = name;
            func.Ordnum = ordnum;
            func = FuncHandler.saveFunc(func);
            this.Close();
            this.DialogResult = DialogResult.OK;
        }

        public Func Func
        {
            get { return func; }
        }
    }
}
